<!--页面组件-->
<template>
  <div>
    <div class="tempxyz addtask">
      <CCard class="cdHead">
        <CCardBody class="card-body" style="margin-top: -70px">
          <div class="cardstyle">
            <CRow>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">任务类型</label>
                <CSelect
                  @change="pushTaskTypeChange($event)"
                  :value.sync="pushTaskType"
                  horizontal
                  :options="taskTypeList"
                  placeholder="请选择"
                  class="input"
                />
              </CCol>
            </CRow>
            <CRow>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">任务名称</label>
                <CInput
                  v-model="addData.taskName"
                  placeholder="请输入任务名称"
                  horizontal
                  class="input"
                />
              </CCol>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">扫描间隔</label>
                <CSelect
                  horizontal
                  :value.sync="addData.crontabExpress"
                  :options="cronList"
                  placeholder="请选择"
                  class="input"
                />
              </CCol>
            </CRow>
            <CRow>
              <CCol sm="6" class="myColScan" style>
                <label class="label">扫描目录</label>
                <CInput
                  v-model="addDataTaskParam.scanDir"
                  placeholder="请输入扫描目录"
                  horizontal
                  class="input"
                />
              </CCol>
              <CCol>
                <CButton
                  color="info"
                  size="sm"
                  @click="selectPushTaskScanDir('scanDir')"
                  class="btnSelectScanDir"
                  >...</CButton
                >
              </CCol>
              <CCol sm="6" class="myColPro" style>
                <label class="label">生产目录</label>
                <CInput
                  v-model="addDataTaskParam.proDir"
                  placeholder="请输入生产目录"
                  horizontal
                  class="input"
                />
              </CCol>
              <CCol>
                <CButton
                  color="info"
                  size="sm"
                  @click="selectPushTaskProDir('proDir')"
                  class="btnSelectProDir"
                  >...</CButton
                >
              </CCol>
            </CRow>
            <CRow>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">组织机构</label>
                <CSelect
                  horizontal
                  :value.sync="addDataTaskParam.enterId"
                  :options="enterpriseList"
                  placeholder="请选择"
                  @change="selectEnterprise($event)"
                  class="input"
                />
              </CCol>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">用户部门</label>
                <CSelect
                  horizontal
                  :value.sync="addDataTaskParam.orgId"
                  :options="organizationList"
                  placeholder="请选择"
                  @change="selectOrganization($event)"
                  class="input"
                />
              </CCol>
            </CRow>
            <CRow>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">用户名</label>
                <CSelect
                  horizontal
                  :value.sync="addDataTaskParam.userId"
                  :options="userNameList"
                  placeholder="请选择"
                  @change="selectUserName($event)"
                  class="input"
                />
              </CCol>
              <CCol sm="6" class="myColtemp" style>
                <label class="label">文件类型</label>
                <CSelect
                  horizontal
                  :options="fileTypeList"
                  :value.sync="addDataTaskParam.finishFlag"
                  placeholder="请选择文件类型"
                  @change="selectFileType($event)"
                  class="input"
                />
              </CCol>
            </CRow>
          </div>
          <table class="table0" v-show="isShow">
            <tbody>
              <tr>
                <td>
                  <div class="position-relative table-responsive1">
                    <table class="table table-hover">
                      <tbody>
                        <tr v-show="showGlobalParameter">
                          <td>
                            <div class="tbHeader">
                              <span style="float: left">基本参数：</span>
                              <CButton
                                class="hoverstyle imgBtn"
                                id="globalParamId"
                                :title="'显示更多参数'"
                                variant="outline"
                                color="info"
                                :flag="'display'"
                                @click="displayDtParamBtn('globalBtn')"
                              >
                                <img
                                  class="jia"
                                  :src="tdRightImg('plus')"
                                  alt
                                />
                              </CButton>
                            </div>
                            <CDataTable
                              :items="globalItems"
                              :fields="fields"
                              class="paramTable globalTag"
                              :header="haveHeader"
                              hover
                            >
                              <template #value="{ item }" style="width: 60%">
                                <td>
                                  <CSelect
                                    v-if="
                                      item.type.name.toLowerCase() === 'select'
                                    "
                                    horizontal
                                    :options="item.constraint"
                                    :value.sync="item.default"
                                    class="inputSelectTd"
                                    placeholder="请选择"
                                  ></CSelect>
                                  <CSelect
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'boolean'
                                    "
                                    horizontal
                                    :options="[
                                      { label: '请选择', value: '' },
                                      { label: '是', value: true },
                                      { label: '否', value: false },
                                    ]"
                                    :value.sync="item.default"
                                    class="inputSelectTd"
                                  ></CSelect>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'dir'
                                    "
                                  >
                                    <template>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserFile(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'file'
                                    "
                                  >
                                    <template horizontal>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserFile(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() ===
                                      'spatialref'
                                    "
                                  >
                                    <template>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserRef(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>

                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'float'
                                    "
                                    class="inputTd"
                                  >
                                    <Form
                                      :model="item"
                                      :rules="ruleCustom"
                                      ref="item"
                                    >
                                      <FormItem
                                        prop="default"
                                        :rules="[
                                          {
                                            validator: (
                                              rule,
                                              value,
                                              callback
                                            ) => {
                                              let data = item;
                                              if (
                                                !data.hasOwnProperty(
                                                  'constraint'
                                                )
                                              )
                                                callback();
                                              let min = data.constraint.min;
                                              let max = data.constraint.max;
                                              let num = parseFloat(value);
                                              var reg = /-?[0-9]*\.?[0-9]+/;
                                              if (
                                                new RegExp(reg).test(value) ==
                                                false
                                              ) {
                                                if (max == undefined) {
                                                  callback(
                                                    '请输入' + min + '以上的值'
                                                  );
                                                } else
                                                  callback(
                                                    '请输入' +
                                                      min +
                                                      '-' +
                                                      max +
                                                      '之间的值'
                                                  );
                                              } else {
                                                if (max == undefined) {
                                                  if (num >= min) callback();
                                                  else
                                                    callback(
                                                      '请输入' +
                                                        min +
                                                        '以上的值'
                                                    );
                                                } else {
                                                  if (num >= min && num <= max)
                                                    callback();
                                                  else {
                                                    if (max == undefined)
                                                      callback(
                                                        '请输入' +
                                                          min +
                                                          '以上的值'
                                                      );
                                                    else
                                                      callback(
                                                        '请输入' +
                                                          min +
                                                          '-' +
                                                          max +
                                                          '之间的值'
                                                      );
                                                  }
                                                }
                                              }
                                            },
                                          },
                                        ]"
                                      >
                                        <Input
                                          v-model="item.default"
                                          clearable
                                          autocomplete="off"
                                          placeholder="请输入浮点数"
                                        />
                                      </FormItem>
                                    </Form>
                                  </div>
                                  <CInput
                                    v-else
                                    v-model="item.default"
                                    clearable
                                    class="inputTd"
                                  />
                                </td>
                              </template>
                            </CDataTable>
                          </td>
                        </tr>
                        <tr
                          v-for="(item2, index) in inputDisplayParamItems"
                          :key="index"
                          v-show="showInputParameter"
                        >
                          <td>
                            <div class="tbHeader">
                              <span style="float: left"
                                >{{ item2.groupName }}算法：</span
                              >
                              <CButton
                                :id="`${item2.groupName}_${index}`"
                                class="hoverstyle imgBtn"
                                :title="'显示更多参数'"
                                variant="outline"
                                color="info"
                                :flag="'display'"
                                @click="displayDtParamBtn(item2, index)"
                              >
                                <img
                                  class="jia"
                                  :src="tdRightImg('plus')"
                                  alt
                                />
                              </CButton>
                            </div>
                            <CDataTable
                              :items="item2"
                              :fields="fields"
                              :class="
                                `${item2.length}` < 1
                                  ? 'paramTable paramTable1 '
                                  : 'paramTable'
                              "
                              :header="haveHeader"
                              hover
                              ref="multipleTable"
                              :title="`${item2.groupName}算法`"
                              :columnFilterValue.sync="ceshi"
                            >
                              <template #value="{ item }" style="width: 60%">
                                <td>
                                  <CSelect
                                    v-if="
                                      item.type.name.toLowerCase() === 'select'
                                    "
                                    horizontal
                                    :options="item.constraint"
                                    :value.sync="item.default"
                                    class="inputSelectTd"
                                    placeholder="请选择"
                                  ></CSelect>
                                  <CSelect
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'boolean'
                                    "
                                    horizontal
                                    :options="[
                                      { label: '请选择', value: '' },
                                      { label: '是', value: true },
                                      { label: '否', value: false },
                                    ]"
                                    :value.sync="item.default"
                                    class="inputSelectTd"
                                  ></CSelect>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'dir'
                                    "
                                  >
                                    <template>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserFile(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'file'
                                    "
                                  >
                                    <template horizontal>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserFile(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() ===
                                      'spatialref'
                                    "
                                  >
                                    <template>
                                      <CInput
                                        v-model="item.default"
                                        clearable
                                        autocomplete="off"
                                        class="inputTd"
                                      />
                                      <CButton
                                        color="info"
                                        size="sm"
                                        @click="browserRef(item)"
                                        class="btnBrowser"
                                        >...</CButton
                                      >
                                    </template>
                                  </div>
                                  <div
                                    v-else-if="
                                      item.type.name.toLowerCase() === 'float'
                                    "
                                    class="inputTd"
                                  >
                                    <Form
                                      :model="item"
                                      :rules="ruleCustom"
                                      ref="item"
                                    >
                                      <FormItem
                                        prop="default"
                                        :rules="[
                                          {
                                            validator: (
                                              rule,
                                              value,
                                              callback
                                            ) => {
                                              let data = item;
                                              if (
                                                !data.hasOwnProperty(
                                                  'constraint'
                                                )
                                              )
                                                callback();
                                              let min = data.constraint.min;
                                              let max = data.constraint.max;
                                              let num = parseFloat(value);
                                              var reg = /-?[0-9]*\.?[0-9]+/;
                                              if (
                                                new RegExp(reg).test(value) ==
                                                false
                                              ) {
                                                if (max == undefined) {
                                                  callback(
                                                    '请输入' + min + '以上的值'
                                                  );
                                                } else
                                                  callback(
                                                    '请输入' +
                                                      min +
                                                      '-' +
                                                      max +
                                                      '之间的值'
                                                  );
                                              } else {
                                                if (max == undefined) {
                                                  if (num >= min) callback();
                                                  else
                                                    callback(
                                                      '请输入' +
                                                        min +
                                                        '以上的值'
                                                    );
                                                } else {
                                                  if (num >= min && num <= max)
                                                    callback();
                                                  else {
                                                    if (max == undefined)
                                                      callback(
                                                        '请输入' +
                                                          min +
                                                          '以上的值'
                                                      );
                                                    else
                                                      callback(
                                                        '请输入' +
                                                          min +
                                                          '-' +
                                                          max +
                                                          '之间的值'
                                                      );
                                                  }
                                                }
                                              }
                                            },
                                          },
                                        ]"
                                      >
                                        <Input
                                          v-model="item.default"
                                          clearable
                                          autocomplete="off"
                                          placeholder="请输入浮点数"
                                        />
                                      </FormItem>
                                    </Form>
                                  </div>
                                  <CInput
                                    v-else
                                    v-model="item.default"
                                    clearable
                                    class="inputTd"
                                  />
                                </td>
                              </template>
                            </CDataTable>
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
          <div class="productDiv" v-show="productLine">
            <Tree
              @on-select-change="selectTree"
              :data="productionLineTree"
              ref="resTree"
              class="proTree"
            ></Tree>
            <Table
              style="width: 50%"
              border
              stripe
              :columns="getColumn2"
              :data="data2"
              max-height="480"
              @on-row-click="getTableData"
            ></Table>
          </div>
        </CCardBody>
      </CCard>
    </div>
    <CModal
      title="选择目录"
      color="info"
      :show.sync="showZtreeModal"
      :closeOnBackdrop="false"
      size="lg"
      centered
    >
      <div style="height: 60px">
        <div>
          <CLink class="px-2" @click="shareMenu(currenItem)">共享文件夹</CLink>
          <br />
          <CLink class="px-2" @click="userMenu(currenItem)">用户文件夹</CLink>
          <!-- <br>
          <CLink class="px-2" >数据订单</CLink>-->
        </div>
        <div class="optiostyle displaySuffix" style="display: none">
          <CInputCheckbox
            label="是否批量"
            type="radio"
            :checked.sync="isBatch"
            value="是否批量"
          />
          <CSelect
            label="过滤条件"
            horizontal
            :options="suffix"
            :value.sync="currenSelectSuffix"
            class="selectSuffix"
          ></CSelect>
          <CButton color="info" @click="suffixSearch" class="suffixBtn"
            >过滤</CButton
          >
        </div>
      </div>
      <div class="treeDiv">
        <ul id="treeDemo" class="ztree"></ul>
      </div>

      <template #header>
        <h5>选择目录</h5>
        <CButtonClose @click="menuCancel" />
      </template>
      <template #footer>
        <CButton @click="menuSaveAs" color="info">另存为</CButton>
        <CButton @click="menuOk" color="info">确定</CButton>
        <CButton @click="menuCancel" color="light ">取消</CButton>
      </template>
    </CModal>
    <CModal
      title="推送任务选择目录"
      color="info"
      :show.sync="showPushTaskZtreeModal"
      :closeOnBackdrop="false"
      size="lg"
      centered
    >
      <div class="treeDiv">
        <ul id="pushTaskTree" class="ztree"></ul>
      </div>

      <template #header>
        <h5>选择目录</h5>
        <CButtonClose @click="pushTaskMenuCancel" />
      </template>
      <template #footer>
        <CButton @click="pushTaskMenuOk" color="info">确定</CButton>
        <CButton @click="pushTaskMenuCancel" color="light">取消</CButton>
      </template>
    </CModal>
    <CModal
      title="表单验证测试"
      color="info"
      :show.sync="testModal"
      :closeOnBackdrop="false"
      size="sm"
      centered
    >
      <Form
        ref="formCustom"
        :model="formCustom"
        :rules="ruleCustom"
        :label-width="80"
      >
        <FormItem label="Age" prop="age">
          <Input type="text" v-model="formCustom.age" />
        </FormItem>
        <FormItem label="count" prop="count">
          <Input type="text" v-model="formCustom.count" />
        </FormItem>
      </Form>
    </CModal>
  </div>
</template>
<script>
const fields = [
  { key: "label", label: "参数名称", _style: "width:20%;text-align:right" },
  { key: "value", label: "参数值", _style: "width:80%;" },
];
export default {
  name: "addTask",
  computed: {
    getColumn2() {
      return [{ key: "workflowName", title: "流程名称", align: "center" }];
    },
  },
  data() {
    var validateuser = function (rule, value, callback) {
      if (!value) {
        return callback(new Error("请输入用户名"));
      } else if (!/^[a-zA-Z\d]+$/.test(value)) {
        return callback(new Error("请正确输入用户名"));
      } else {
        callback();
      }
    };
    var validateAge = (rule, value, callback) => {
      if (!Number.isInteger(+value)) {
        callback(new Error("请输入数字"));
      } else {
        callback();
      }
    };
    var validateCount = (rule, value, callback) => {
      if (!Number.isInteger(+value)) {
        callback(new Error("请输入数字"));
      } else if (Number.isInteger(+value)) {
        let num = Number(value);
        let length = value.length;
        if (length < 3) {
          callback(new Error("请输入长度为3的数字"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };

    return {
      isShow: false,
      testModal: false,
      ceshi: null,
      inputDisplayParamItems: [], //表格默认显示
      inputParamItems: [], //表格显示和隐藏全部参数
      hiddenDtParam: [], //表格隐藏参数
      displayDtParam: [], //表格显示参数
      productName: "",
      productLine: false,
      productionLineTree: [],
      fields,
      showInputParameter: false,
      showGlobalParameter: false,
      // showMoreTr: false,
      // showBtn: true,
      // hideBtn: false,
      // hideTr: false,
      data: [],
      data2: [],
      sate: "",
      sensor: "",
      flowId: "",
      sourceId: 0,
      formCustom: {
        age: 10,
        count: 1,
      },
      ruleCustom: {
        age: [
          { required: true, message: "年龄不能为空", trigger: "blur" },
          { validator: validateAge, trigger: "blur" },
        ],
        count: [
          { required: true, message: "数量不能为空", trigger: "blur" },
          { validator: validateCount, trigger: "blur" },
        ],
        default: [
          { required: true, message: "请输入数字", trigger: "blur" },
          { validator: validateCount, trigger: "blur" },
        ],
      },
      autoTask: [],
      sateList_temp1: [],
      sersorList_temp1: [],
      sateList: [
        {
          value: "",
          label: "请选择",
        },
        {
          value: "GF1",
          label: "GF1",
        },
        {
          value: "GF2",
          label: "GF2",
        },
        {
          value: "ZY3",
          label: "ZY3",
        },
      ],
      sersorList: [
        {
          value: "",
          label: "请选择",
        },
        {
          value: "PMS",
          label: "PMS",
        },
        {
          value: "WFV",
          label: "WFV",
        },
      ],
      cronList: [],
      pushTaskType: "EmergencyTask",
      bIsScanDir: true,
      taskTypeList: [
        {
          value: "EmergencyTask",
          label: "应急任务",
        },
        {
          value: "RoutineTask",
          label: "常规任务",
        },
        {
          value: "ModisTask",
          label: "MODIS任务",
        },
      ],
      typeList: [],
      items: [],
      globalItems: [],
      addData: {
        flowName: "",
        crontabExpress: "",
        flowId: "",
        sourceId: 0,
        taskName: "",
        taskParameter: "",
      },
      addDataTaskParam: {
        scanDir: "",
        proDir: "",
        finishFlag: "",
        taskOwner: "", //任务发起者
        department: "", //发起者部门
        enterId: -1, //组织机构
        orgId: -1, //部门
        userId: -1, //用户
      },
      fileTypeList: [".gz", ".zip"],
      enterpriseList: [],
      organizationList: [],
      userNameList: [],
      showPushTaskZtreeModal: false,
      showZtreeModal: false,
      isBatch: false,
      suffix: [],
      currenSelectSuffix: "",
      haveHeader: false,
    };
  },
  watch: {
    groupName(newVal, oldVal) {
      if (newVal.length >= 50) {
        this.$Message.error("任务名称长度不得超过50个字符");
      }
    },
    flowId(newVal, oldVal) {
      this.flowId = newVal;
      this.getParamList(newVal);
    },
    inputDisplayParamItems: {
      handler(newval, oldval) {},
      deep: true,
    },
  },
  mounted() {
    this.source();
    this.getModelCategoryTree();
    this.searchAllProductionLine();
    this.getCronList();
    this.getEnterpriseList();
  },
  methods: {
    selectFileType(event) {
      this.addDataTaskParam.finishFlag = event.target.value;
    },
    tdRightImg(type) {
      let img = {
        plus: require("./../../assets/icons/leftArrow.svg"),
        reduce: require("./../../assets/icons/downArrow.svg"),
      };
      return img[type];
    },
    getTableData(row) {
      this.isShow = true;
      this.productName = row.workflowName;
      this.flowId = row.id;
      this.addData.flowName = row.workflowName;
      this.addData.flowId = `${row.id}`;
      this.productLine = false;
    },
    showProduct() {
      this.productLine = true;
    },
    //查询左侧树
    getModelCategoryTree() {
      let self = this;
      self.productionLineTree = [];
      let path = this.$api.processingApi.groupTree;
      this.http.get(path).then((res) => {
        self.loading = false;
        if ((res.status = 200)) {
          if (res.data.data.length > 0) {
            self.productionLineTree = res.data.data;
            self.productionLineTree[0].selected = false;
            self.productId = self.productionLineTree[0].id;
            if (self.productionLineTree[0].children.length > 0) {
              this.children = true;
            } else {
              this.children = false;
            }
          } else {
            self.productId = "0";
            self.pid = "0";
          }
        } else {
          this.$Message.error(res.data.message);
        }
      });
      // this.getProduct(self.productId);
    },
    //查看所有流程
    searchAllProductionLine() {
      let self = this;
      let path = this.$api.processingApi.search;
      this.http.get(path).then((res) => {
        if (res.data.code == 0) {
          let getData = res.data.data;
          let newGetData = [];
          for (var i = 0; i < getData.length; i++) {
            let newTemp = {};
            newTemp.id = getData[i].id;
            newTemp.workflowName = getData[i].workflowName;
            newGetData.push(newTemp);
          }
          console.log(newGetData);
          self.data2 = newGetData;
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    getProduct(groupId) {
      let path = this.$api.processingApi.search;
      let param = {
        groupId: groupId,
      };
      this.http.get(path, param).then((res) => {
        if (res.data.code == 0) {
          let newData = res.data.data;
          this.data2 = newData;
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    selectTree() {
      let self = this;
      self.productId = this.$refs.resTree.getSelectedNodes()[0].id;
      console.log("当前节点信息", this.$refs.resTree.getSelectedNodes());
      self.pid = this.$refs.resTree.getSelectedNodes()[0].parentId;
      if (this.$refs.resTree.getSelectedNodes()[0].children.length > 0) {
        this.children = true;
      } else {
        this.children = false;
      }
      this.getProduct(self.productId);
    },

    getParamList(val) {
      // this.getParamListNew()
      // return
      let workflowId = this.workflowId;
      // console.log("点击的workflowId", workflowId);
      let defaultPath = this.$api.processingApi.searchProcessParameters;
      let param1 = {
        workFlowId: val,
      };
      this.displayDtParam = []; //表格显示数据置空
      this.hiddenDtParam = [];
      this.http.get(defaultPath, param1).then((res) => {
        let data = res.data;

        if (data.success) {
          let inputParam = JSON.parse(data.data.processParameters).inputParam;
          let globalParam = JSON.parse(data.data.processParameters).globalParam;
          let params = JSON.parse(data.data.processParameters);

          //参数显示隐藏
          this.showBtn = true;
          this.showInputParameter = true;
          for (let i = 0; i < inputParam.length; i++) {
            let temp = inputParam[i];
            let display = [];
            let hidden = [];
            for (let j = 0; j < temp.length; j++) {
              let tempValue = temp[j];
              let defaultVal = tempValue.default;
              if (
                tempValue.type.name.toLowerCase() === "select" &&
                typeof defaultVal === "object"
              ) {
                tempValue.default = defaultVal.value;
              }
              // if ((defaultVal != null && defaultVal != "") || defaultVal === 0)
              if (tempValue.hasOwnProperty("display")) {
                if (tempValue.display) display.push(tempValue);
                else hidden.push(tempValue);
              } else {
                display.push(tempValue);
              }
            }
            if (hidden.length < 1) hidden.isDisplay = false;
            display.groupName = temp[0].groupName;
            hidden.groupName = temp[0].groupName;
            this.hiddenDtParam.push(hidden); //显示和隐藏的时候需要更新维护
            this.displayDtParam.push(display); //只在表格初始化的时候用一次
          }
          let dd = this.displayDtParam;

          console.log("520已改为查询全局参数的", params);
          if (
            params.globalParam == undefined ||
            params.globalParam.length < 1
          ) {
            this.showInputParameter = true;
            this.showGlobalParameter = false;

            this.inputDisplayParamItems = this.displayDtParam; //inputParam;
            this.inputParamItems = inputParam; //表格参数全部数据
            this.globalItems = null;
          } else {
            this.showInputParameter = false;
            this.showGlobalParameter = true;
            this.inputDisplayParamItems = this.displayDtParam; // inputParam;
            this.inputParamItems = inputParam;
            this.globalItems = globalParam;
            // console.log("全局参数" + JSON.stringify(globalParam));
          }
        } else {
          this.$Message.error(res.data.message);
        }

        this.$nextTick(() => {
          this.setDisplayHidBtnStyle();
        });
      });
    },
    setDisplayHidBtnStyle() {
      //对显示隐藏按钮样式做判断
      let hiddeItem = this.hiddenDtParam;
      let id = "";
      hiddeItem.forEach((element, index) => {
        id = element.groupName + "_" + index;
        let img = $("#" + id).find("img");
        id = this.getFormatId(id);
        if (element.length < 1) {
          $("#" + id).css("display", "none");
        } else {
          $("#" + id).css("display", "block");
          img.attr("src", this.tdRightImg("plus"));
        }
      });
    },
    //解决Dom元素标签id为特殊字符 根据元素id获取Dom对象失败问题
    getFormatId(srcString) {
      // 转义之后的结果
      var result = srcString;
      // javascript正则表达式中的特殊字符
      var jsSpecialChars = [
        "\\",
        "^",
        "$",
        "*",
        "?",
        ".",
        "+",
        "(",
        ")",
        "[",
        "]",
        "|",
        "{",
        "}",
      ];

      // jquery中的特殊字符,不是正则表达式中的特殊字符
      var jquerySpecialChars = [
        "~",
        "`",
        "@",
        "#",
        "%",
        "&",
        "=",
        "'",
        '"',
        ":",
        ";",
        "<",
        ">",
        ",",
        "/",
      ];

      for (var i = 0; i < jsSpecialChars.length; i++) {
        result = result.replace(
          new RegExp("\\" + jsSpecialChars[i], "g"),
          "\\" + jsSpecialChars[i]
        );
      }

      for (var i = 0; i < jquerySpecialChars.length; i++) {
        result = result.replace(
          new RegExp(jquerySpecialChars[i], "g"),
          "\\" + jquerySpecialChars[i]
        );
      }
      return result;
    },
    displayDtParamBtn(data, index) {
      let id = "";
      let groupName = "";
      let btnName = "";

      if (data === "globalBtn") {
        btnName = "globalBtn";
        //基本参数右侧控制按钮
        id = "globalParamId";
      } else {
        //算法参数右上角显示控制按钮
        groupName = data.groupName; //当前表格算法分组
        id = groupName + "_" + index; //当前td id
      }

      let flag = $("#" + id).attr("flag");
      let img = $("#" + id).find("img");
      if (flag == "display") {
        //显示更多
        $("#" + id).attr("flag", "hidden");
        $("#" + id).attr("title", "隐藏参数");
        img.attr("src", this.tdRightImg("reduce"));

        if (btnName !== "" && data === btnName)
          this.showInputParameter = !this.showInputParameter;
        else this.displayAlgoParam(index);
      } else if (flag == "hidden") {
        //隐藏参数
        $("#" + id).attr("flag", "display");
        $("#" + id).attr("title", "显示更多参数");
        img.attr("src", this.tdRightImg("plus"));

        if (btnName !== "" && data === btnName)
          this.showInputParameter = !this.showInputParameter;
        else this.hiddenAlgoParam(index);
      }
    },
    //显示表格隐藏算法参数
    displayAlgoParam(index) {
      //let groupName = data[0].groupName; //当前表格算法分组
      let currentTableParam = this.inputDisplayParamItems[index];
      let hiddenParam = this.hiddenDtParam[index];

      for (let j = 0; j < hiddenParam.length; j++) {
        let tempHid = hiddenParam[j];
        currentTableParam.push(tempHid);
      }
    },
    // 隐藏表格显示算法参数
    hiddenAlgoParam(index) {
      /**
       * 思路：1、获取当前表格数据源currentTableParam：根据当前点击的表格索引获取当前表格参数
       * 2、移除表格数据源要隐藏的参数：currentTableParam和全局的隐藏参数hiddenParam进行比对 如果hiddenParam的参数和currentTableParam参数相同则移除currentTableParam对应的参数
       * 3、更新隐藏参数列表：在2的基础上判断当前全局的hiddenParam和已经显示到表格中的隐藏参数值是否发生变化 是 用currentTableParam最新的参数替换隐藏参数中对应参数
       */
      let currentTableParam = this.inputDisplayParamItems[index];
      let hiddenParam = this.hiddenDtParam[index];

      for (let i = 0; i < currentTableParam.length; i++) {
        let tempItem = currentTableParam[i];
        hiddenParam.forEach((element, index1) => {
          if (tempItem.name === element.name) {
            currentTableParam.splice(i, 1); //删除索引i的1个元素
            i--; //必须有
          }
        });
      }
    },
    getParamListNew() {
      let workflowId = this.workflowId;
      let path =
        this.$api.processingApi.productLineQuery + workflowId + "/findParam";
      this.http.get(path).then((res) => {
        let data = res.data;
        console.log("算法原始参数", data);
        let isDeafault = false;
        if (data.code == 0) {
          let newTempList = [];
          for (var i in data.data) {
            let tempList = [];
            let newDataList = [];
            tempList = data.data[i]["input-parameters"];

            newDataList = this.getData(
              tempList,
              data.data[i].name,
              newDataList,
              isDeafault
            );
            newTempList.push(newDataList);
          }
          this.items = newTempList;
          console.log("表格渲染原始显示参数", newTempList);
        } else {
          this.items = [];
          this.$Message.error(res.data.message);
          this.$Message.error(res.data.message);
        }
      });
    },

    getData(tempList, groupName, newList, isDeafault) {
      let arrData = tempList;
      var tempInfo = [];
      var type = "";
      var enumInfo = "";
      for (var index in arrData) {
        tempInfo = arrData[index];
        type = tempInfo.type.name.toLowerCase();
        enumInfo = tempInfo.constraint;
        let enumObjArr = [];
        if (type === "select") {
          if (isDeafault) {
            enumObjArr = tempInfo.constraint;
          } else {
            enumInfo = tempInfo.constraint.values;
            for (var key in enumInfo) {
              let newObj = new Object();
              newObj.value = key;
              newObj.label = enumInfo[key];
              enumObjArr.push(newObj);
            }
          }
          delete tempInfo.constraint;
          tempInfo.constraint = enumObjArr;
        }
        if (!tempInfo.hasOwnProperty("default")) {
          tempInfo.default = "";
        }
        if (groupName != "") tempInfo.groupName = groupName;
        newList.push(tempInfo);
      }
      return newList;
    },

    changeInput(index) {
      this.listproductLine.map((v, i) => {
        if (i == index) {
          v.isCheck = true;
        } else {
          v.isCheck = false;
        }
      });
      let name = this.listproductLine[index].workflowName;
      let currentTime = this.getTime();
      // this.taskName = name + "_" + this.userName + "_" + currentTime;
    },

    changeInputLevel(index) {
      this.options.map((v, i) => {
        if (i == index) {
          v.isCheck = true;
          this.priorityLevel = v.value;
        } else v.isCheck = false;
      });
    },
    getTime() {
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      var hours = date.getHours();
      var minutes = date.getMinutes();
      var seconds = date.getSeconds();
      if (month < 10) {
        month = "0" + month;
      }
      if (day < 10) {
        day = "0" + day;
      }
      let time = year + month + day + " " + hours + ":" + minutes;
      return time;
    },

    source() {
      let self = this;
      let path = this.$api.processingApi.source;
      this.http.get(path).then((res) => {
        if (res.data.code == 0) {
        } else {
          console.log("查询sourceid错误");
        }
      });
    },
    menuCancel() {
      this.reset();
    },
    menuOk() {
      let isBatch = this.isBatch;
      var treeObj = $.fn.zTree.getZTreeObj("treeDemo"),
        nodes = treeObj.getCheckedNodes(true);
      let tempNode = "";
      let info = "";
      for (var index in nodes) {
        tempNode = nodes[index];
        if (
          this.currenItem.type.name.toLowerCase() === "file" &&
          tempNode.isParent
        )
          continue;
        if (info == "") info = tempNode.id;
        else if (isBatch) {
          info += "#HT#" + tempNode.id;
        } else {
          info += "#TASK#" + tempNode.id;
        }
      }

      console.log("zuobio之前的参考" + info);
      this.currenItem.default = info;
      this.reset();
    },
    // 过滤条件搜索
    suffixSearch() {
      var treeObj = $.fn.zTree.getZTreeObj("treeDemo"),
        nodes = treeObj.getCheckedNodes(true);
      if (nodes.length < 1) {
        this.$Message.warning("没有选中的文件或文件夹");
        return;
      }
      for (var i in nodes) {
        this.getFile(treeObj, nodes[i]);
      }
    },
    // 文件另存为modal界面初始化
    menuSaveAs() {
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      if (treeObj == null) {
        this.$Message.warning("请选择文件夹！");
        return;
      }

      let selectNodes = treeObj.getSelectedNodes();
      if (selectNodes.length < 1) {
        this.$Message.warning("请选择文件夹节点！");
        return;
      }
      if (!selectNodes[0].isParent) {
        this.$Message.warning("请选择文件夹！");
        return;
      }
      this.newFileName = ""; //界面文件名置为空
      this.saveAsModal = true;

      if (this.currenItem.type.name.toLowerCase() === "file") {
        self.isFile = true;
        $(".saveFile").css("display", "block");
        $(".saveFolder").css("display", "none");
      }
      //用于新增文件或文件夹标识
      else {
        $(".saveFile").css("display", "none");
        $(".saveFolder").css("display", "block");
        self.isFile = false;
      }
    },
    saveAsFileOK() {
      let fileName = this.newFileName;
      this.saveAsModal = false;
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      let selectNodes = treeObj.getSelectedNodes();
      let newNode = "";
      if (fileName == null || fileName == "") {
        this.$Message.warning("文件名或文件夹名称为空，请重写填写");
      }
      if (isFile) {
        //文件 判断文件名是否符合带后缀
        let a = fileName.split("").reverse().join("");
        let b = a.substring(0, a.search(/\./)).split("").reverse().join("");
        if (b == null || b == "") {
          this.$Message.warning("该文件名无效，没有后缀");
          return;
        }
        newNode = {
          name: fileName,
          id: selectNodes[0].id + "/" + fileName,
          isParent: false,
        };
      } else
        newNode = {
          name: fileName,
          id: selectNodes[0].id + "/" + fileName,
          isParent: true,
        };
      if (newNode == null) return;
      treeObj.addNodes(selectNodes[0], 0, newNode, true); //新增节点放在文件夹的顶层并默认选择
      let node = selectNodes[0].children[0];
      node.checked = true;
      treeObj.updateNode(node);
    },

    saveAsFileCancel() {
      this.saveAsModal = false;
    },

    // 任务类型选择变化
    pushTaskTypeChange(event) {
      let self = this;
      let typeValue = event.target.value;
      self.pushTaskType = typeValue;
    },
    // 应急推送任务扫描目录选择
    selectPushTaskScanDir(type) {
      this.bIsScanDir = true;
      this.showPushTaskZtreeModal = true;
      this.pushTaskMenu(type);
    },
    // 应急推送任务生产目录选择
    selectPushTaskProDir(type) {
      this.bIsScanDir = false;
      this.showPushTaskZtreeModal = true;
      this.pushTaskMenu(type);
    },
    // 应急推送任务扫描目录、生产目录Ztree设置
    pushTaskMenuSetting(urlPath) {
      let checkType = { Y: "", N: "" }; //父与子的关联去掉
      let setting = {
        check: {
          enable: true,
          nocheckInherit: false,
          chkboxType: checkType,
        },
        data: {
          simpleData: {
            enable: true,
          },
        },
        callback: {
          beforeClick: this.beforeClick,
          onClick: this.zTreeOnClick,
          onCheck: this.zTreePushTaskOnCheck,
          onExpand: this.zTreeOnClick,
        },
      };

      this.http.get(urlPath).then((res) => {
        let data = res.data;
        if (data.success == true) {
          $.fn.zTree.init($("#pushTaskTree"), setting, data.data);
        }
      });
    },
    pushTaskMenu(type) {
      let treeObj = $.fn.zTree.getZTreeObj("pushTaskTree");
      if (treeObj != null) {
        var nodes = treeObj.getNodes();
        for (var i = nodes.length - 1; i >= 0; i--) {
          treeObj.removeNode(nodes[i]);
        }
      }

      let path; //1为共享文件夹,2为用户文件夹,3为紧急推送扫描文件夹,4为应急任务生产根目录,5为常规推送生产根目录,6为自动推送Modis生产根目录,7为自动推送Modis扫描根目录
      if (type == "scanDir") {
        if (this.pushTaskType == "EmergencyTask") {
          path = this.$api.processingApi.fileRootPath + 3;
        } else if (this.pushTaskType == "RoutineTask") {
          path = this.$api.processingApi.fileRootPath + 1;
        } else if (this.pushTaskType == "ModisTask") {
          path = this.$api.processingApi.fileRootPath + 7;
        } else {
          path = this.$api.processingApi.fileRootPath + 1;
        }
      } else {
        if (this.pushTaskType == "EmergencyTask") {
          path = this.$api.processingApi.fileRootPath + 4;
        } else if (this.pushTaskType == "RoutineTask") {
          path = this.$api.processingApi.fileRootPath + 5;
        } else if (this.pushTaskType == "ModisTask") {
          path = this.$api.processingApi.fileRootPath + 6;
        } else {
          path = this.$api.processingApi.fileRootPath + 1;
        }
      }
      this.pushTaskMenuSetting(path);
    },
    zTreePushTaskOnCheck(event, treeId, treeNode) {
      var treeObj = $.fn.zTree.getZTreeObj(treeId),
        nodes = treeObj.getCheckedNodes(true);

      if (!treeNode.isParent) {
        this.$Message.warning("请选择文件夹！");
        treeNode.checked = false;
        treeObj.updateNode(treeNode);
        return;
      }
      if (!this.bIsScanDir && nodes.length > 1) {
        //限制单个文件夹
        this.$Message.warning("生产目录只能选择一个文件夹！");
        treeNode.checked = false;
        treeObj.updateNode(treeNode);
        return;
      }
    },
    pushTaskMenuOk() {
      let treeObj = $.fn.zTree.getZTreeObj("pushTaskTree"),
        nodes = treeObj.getCheckedNodes(true);
      let tempNode = "";
      let info = "";
      for (var index in nodes) {
        tempNode = nodes[index];
        if (info == "") {
          info = tempNode.id;
        } else {
          info += ";" + tempNode.id;
        }
      }

      if (this.bIsScanDir) {
        this.addDataTaskParam.scanDir = info;
      } else {
        this.addDataTaskParam.proDir = info;
      }

      this.pushTaskReset();
    },
    pushTaskMenuCancel() {
      this.pushTaskReset();
    },
    pushTaskReset() {
      var treeObj;
      this.showPushTaskZtreeModal = false;
      treeObj = $.fn.zTree.getZTreeObj("pushTaskTree");
      if (treeObj == null) return;

      var nodes = treeObj.getNodes();
      for (var i = nodes.length - 1; i >= 0; i--) {
        treeObj.removeNode(nodes[i]);
      }
    },

    menuSetting(item, urlPath) {
      $(".displaySuffix").css("display", "block");
      let checkType = { Y: "", N: "" }; //父与子的关联去掉
      if (item.type.name.toLowerCase() === "file") {
        checkType = { Y: "s", N: "ps" };
      }
      let setting = {
        check: {
          enable: true,
          nocheckInherit: false,
          chkboxType: checkType,
        },
        data: {
          simpleData: {
            enable: true,
          },
        },
        callback: {
          beforeClick: this.beforeClick,
          onClick: this.zTreeOnClick,
          onCheck: this.zTreeOnCheck,
          onExpand: this.zTreeOnClick,
        },
      };

      this.http.get(urlPath).then((res) => {
        let data = res.data;
        if (data.success == true) {
          $.fn.zTree.init($("#treeDemo"), setting, data.data);
        }
      });
    },
    shareMenu(item) {
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      if (treeObj != null) {
        var nodes = treeObj.getNodes();
        for (var i = nodes.length - 1; i >= 0; i--) {
          treeObj.removeNode(nodes[i]);
        }
      }
      let path = this.$api.processingApi.fileRootPath + 1; //1 共享 2 用户
      this.menuSetting(item, path);
    },

    userMenu(item) {
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      if (treeObj != null) {
        var nodes = treeObj.getNodes();
        for (var i = nodes.length - 1; i >= 0; i--) {
          treeObj.removeNode(nodes[i]);
        }
      }
      let path = this.$api.processingApi.fileRootPath + 2; //1 共享 2 用户
      this.menuSetting(item, path);
    },

    zTreeOnClick(event, treeId, treeNode) {
      let path = this.$api.processingApi.getFileListByPath;
      let param = {
        path: treeNode.id,
      };
      var treeObj = $.fn.zTree.getZTreeObj(treeId);
      var node = treeObj.getNodeByParam("id", treeNode.id);
      treeObj.selectNode(node);
      let sNode = treeObj.getSelectedNodes();
      if (sNode.length > 0) {
        let zAsync = sNode[0].zAsync;
        treeObj.reAsyncChildNodes(treeNode, "refresh");
        if (zAsync) {
        } else {
          this.http.get(path, param).then((res) => {
            let data = res.data;
            if (data.success == true) {
              treeNode.halfCheck = false;
              treeObj.addNodes(treeNode, data.data, false);
              sNode[0].zAsync = true;
            }
          });
        }
      }
    },
    //////////////////////////////////以下为目录浏览功能//////////////////////////////////
    //文件浏览功能
    browserFile(item) {
      let self = this;
      self.currenItem = item;
      this.showZtreeModal = true;
      this.isRefModal = false;

      if (!item.hasOwnProperty("constraint")) {
        self.suffix = [];
        self.currenSelectSuffix = "";
        return;
      }
      let extensions = item.constraint.extensions.split(/[,;]/);
      let tempSuffix = [];
      for (var i in extensions) {
        let newObj = new Object();
        let name = extensions[i];
        newObj.value = name.substring(2, name.length);
        newObj.label = name.substring(2, name.length);
        tempSuffix.push(newObj);
      }
      self.suffix = tempSuffix;
      self.currenSelectSuffix = tempSuffix[0].value;
    },

    browserRef(item) {
      this.isRefModal = true;
      this.showZtreeRefModal = true;
      let self = this;
      self.currenItem = item;
      let path = this.$api.processingApi.browserRefPath;
      let setting = {
        check: {
          enable: true,
          nocheckInherit: false,
          chkboxType: { Y: "", N: "" },
        },
        data: {
          simpleData: {
            enable: true,
          },
        },
        callback: {
          // beforeClick: this.beforeClick,
          // onClick: this.zTreeOnClick,
          // onCheck: this.zTreeOnCheck,
          // onExpand: this.zTreeOnClick
        },
      };
      this.http.get(path).then((res) => {
        let data = res.data;
        if (data.success == true) {
          $.fn.zTree.init($("#treeDemo1"), setting, data.data);
          console.log("refTree", data.data);
        }
      });
    },

    menuSetting(item, urlPath) {
      $(".displaySuffix").css("display", "block");
      let checkType = { Y: "", N: "" }; //父与子的关联去掉
      if (item.type.name.toLowerCase() === "file") {
        checkType = { Y: "s", N: "ps" };
      }
      let setting = {
        check: {
          enable: true,
          nocheckInherit: false,
          chkboxType: checkType,
        },
        data: {
          simpleData: {
            enable: true,
          },
        },
        callback: {
          beforeClick: this.beforeClick,
          onClick: this.zTreeOnClick,
          onCheck: this.zTreeOnCheck,
          onExpand: this.zTreeOnClick,
        },
      };

      this.http.get(urlPath).then((res) => {
        let data = res.data;
        if (data.success == true) {
          $.fn.zTree.init($("#treeDemo"), setting, data.data);
        }
      });
    },
    shareMenu(item) {
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      if (treeObj != null) {
        var nodes = treeObj.getNodes();
        for (var i = nodes.length - 1; i >= 0; i--) {
          treeObj.removeNode(nodes[i]);
        }
      }
      let path = this.$api.processingApi.fileRootPath + 1; //1 共享 2 用户
      this.menuSetting(item, path);
    },

    userMenu(item) {
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      if (treeObj != null) {
        var nodes = treeObj.getNodes();
        for (var i = nodes.length - 1; i >= 0; i--) {
          treeObj.removeNode(nodes[i]);
        }
      }
      let path = this.$api.processingApi.fileRootPath + 2; //1 共享 2 用户
      this.menuSetting(item, path);
    },

    zTreeOnClick(event, treeId, treeNode) {
      let path = this.$api.processingApi.getFileListByPath;
      let param = {
        path: treeNode.id,
      };
      var treeObj = $.fn.zTree.getZTreeObj(treeId);
      var node = treeObj.getNodeByParam("id", treeNode.id);
      treeObj.selectNode(node);
      let sNode = treeObj.getSelectedNodes();
      if (sNode.length > 0) {
        let zAsync = sNode[0].zAsync;
        treeObj.reAsyncChildNodes(treeNode, "refresh");
        if (zAsync) {
        } else {
          this.http.get(path, param).then((res) => {
            let data = res.data;
            if (data.success == true) {
              treeNode.halfCheck = false;
              treeObj.addNodes(treeNode, data.data, false);
              sNode[0].zAsync = true;
            }
          });
        }
      }
    },

    zTreeOnCheck(event, treeId, treeNode) {
      var treeObj = $.fn.zTree.getZTreeObj(treeId),
        nodes = treeObj.getCheckedNodes(true);
      let item = this.currenItem;

      if (item.type.name.toLowerCase() === "file") {
        //文件筛选过滤
        // if (!item.type.plural && nodes.length > 1) {
        //   //限制单个文件
        //   this.$Message.error("该文件路径限制只能选一个文件哦！");
        //   treeNode.checked = false;
        //   treeObj.updateNode(treeNode);
        //   return;
        // }
        this.getFile(treeObj, treeNode);
        return;
      }
      if (item.type.name.toLowerCase() === "dir") {
        if (!treeNode.isParent) {
          this.$Message.warning("请选择文件夹！");
          treeNode.checked = false;
          treeObj.updateNode(treeNode);
          return;
        }
        if (!item.type.plural && nodes.length > 1) {
          //限制单个文件夹
          this.$Message.warning("当前算法限制只能选一个文件夹哦！");
          treeNode.checked = false;
          treeObj.updateNode(treeNode);
          return;
        }
      }
    },

    getFile(treeObj, treeNode) {
      let tempNode;
      let childsArr = [];

      if (treeNode.hasOwnProperty("children") && treeNode.checked) {
        tempNode = treeNode.children;
        this.getChildsByTreeNode(treeNode, childsArr);
        this.getFileBySuffix(treeObj, childsArr);
      } else if (treeNode.checked) {
        let suffix = this.currenSelectSuffix;
        let fileName = treeNode.name.toLowerCase();
        let regValue = fileName.substring(
          fileName.length - suffix.length,
          fileName.length
        );
        if (
          !suffix.hasOwnProperty("value") &&
          regValue !== suffix.toLowerCase()
        ) {
          treeNode.checked = false;
          this.$Message.warning("文件格式不符合过滤条件");
        }
        treeObj.updateNode(treeNode);
      }
    },

    getChildsByTreeNode(treeNode, childsArr) {
      if (treeNode.isParent) {
        //是父节点获取所有子节点
        let childs = treeNode.children;
        for (var i in childs) {
          childsArr.push(childs[i]);
          this.getChildsByTreeNode(childs[i], childsArr);
        }
      }
      return childsArr;
    },
    getFileBySuffix(treeObj, childsFiles) {
      let nodes = childsFiles;
      let fileName;
      let regValue;
      let tempNode;
      let suffix = this.currenSelectSuffix;
      if (nodes.length == undefined) {
        if (!nodes.isParent) {
          //文件
          fileName = nodes.name.toLowerCase();
          regValue = fileName.substring(
            fileName.length - suffix.length,
            fileName.length
          );
          if (regValue === suffix) nodes.checked = true;
          else nodes.checked = false;
          treeObj.updateNode(nodes);
        }
      }
      for (var i = 0; i < nodes.length; i++) {
        tempNode = nodes[i];
        this.getFileBySuffix(treeObj, tempNode);
        if (tempNode.isParent) {
          let tempChilds = tempNode.children;
          let num = 0;
          for (var m in tempChilds) {
            if (tempChilds[m].checked) num++;
            if (num > 1) break;
          }
          if (num < 1) {
            tempNode.checked = false;
            treeObj.updateNode(tempNode);
          }
        }
      }
    },

    menuOk() {
      let isBatch = this.isBatch;
      var treeObj = $.fn.zTree.getZTreeObj("treeDemo"),
        nodes = treeObj.getCheckedNodes(true);
      let tempNode = "";
      let info = "";
      for (var index in nodes) {
        tempNode = nodes[index];
        if (
          this.currenItem.type.name.toLowerCase() === "file" &&
          tempNode.isParent
        )
          continue;
        if (info == "") info = tempNode.id;
        else if (isBatch) {
          info += "#HT#" + tempNode.id;
        } else {
          info += "#TASK#" + tempNode.id;
        }
      }

      console.log("zuobio之前的参考" + info);
      this.currenItem.default = info;
      this.reset();
    },
    menuRefOk() {
      let isBisRefModalatch = this.isRefModal;
      var treeObj = $.fn.zTree.getZTreeObj("treeDemo1"),
        nodes = treeObj.getCheckedNodes(true);
      let tempNode = "";
      let info = "";
      for (let i in nodes) {
        if (nodes.length > 1) {
          this.$Message.warning("请选择一个参考坐标系");
          break;
        }
        info = nodes[0].content;
        console.log("之前的参考" + info);
        info = info.replace(/[\r\n]/g, "");
        console.log("之后的参考" + info);
        this.currenItem.default = info; //nodes[0].name;
        this.reset();
      }
    },
    menuCancel() {
      this.reset();
    },

    //目录选择页面 重置
    reset() {
      let isRefModal = this.isRefModal;
      var treeObj;
      if (isRefModal) {
        this.showZtreeRefModal = false;
        treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
      } else {
        this.showZtreeModal = false;
        $(".displaySuffix").css("display", "none");
        treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      }

      if (treeObj == null) return;
      var nodes = treeObj.getNodes();
      for (var i = nodes.length - 1; i >= 0; i--) {
        treeObj.removeNode(nodes[i]);
      }
    },

    // 过滤条件搜索
    suffixSearch() {
      var treeObj = $.fn.zTree.getZTreeObj("treeDemo"),
        nodes = treeObj.getCheckedNodes(true);
      if (nodes.length < 1) {
        this.$Message.warning("没有选中的文件或文件夹");
        return;
      }
      for (var i in nodes) {
        this.getFile(treeObj, nodes[i]);
      }
    },

    // 文件另存为modal界面初始化
    menuSaveAs() {
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      if (treeObj == null) {
        this.$Message.warning("请选择文件夹！");
        return;
      }

      let selectNodes = treeObj.getSelectedNodes();
      if (selectNodes.length < 1) {
        this.$Message.warning("请选择文件夹节点！");
        return;
      }
      if (!selectNodes[0].isParent) {
        this.$Message.warning("请选择文件夹！");
        return;
      }
      this.newFileName = ""; //界面文件名置为空
      this.saveAsModal = true;

      if (this.currenItem.type.name.toLowerCase() === "file") {
        self.isFile = true;
        $(".saveFile").css("display", "block");
        $(".saveFolder").css("display", "none");
      }
      //用于新增文件或文件夹标识
      else {
        $(".saveFile").css("display", "none");
        $(".saveFolder").css("display", "block");
        self.isFile = false;
      }
    },

    saveAsFileOK() {
      let fileName = this.newFileName;
      this.saveAsModal = false;
      let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
      let selectNodes = treeObj.getSelectedNodes();
      let newNode = "";
      if (!fileName) {
        this.$Message.warning("文件名或文件夹名称为空，请重写填写");
      }
      if (isFile) {
        //文件 判断文件名是否符合带后缀
        let a = fileName.split("").reverse().join("");
        let b = a.substring(0, a.search(/\./)).split("").reverse().join("");
        if (b == null || b == "") {
          this.$Message.warning("该文件名无效，没有后缀");
          return;
        }
        newNode = {
          name: fileName,
          id: selectNodes[0].id + "/" + fileName,
          isParent: false,
        };
      } else
        newNode = {
          name: fileName,
          id: selectNodes[0].id + "/" + fileName,
          isParent: true,
        };
      if (newNode == null) return;
      treeObj.addNodes(selectNodes[0], 0, newNode, true); //新增节点放在文件夹的顶层并默认选择
      let node = selectNodes[0].children[0];
      node.checked = true;
      treeObj.updateNode(node);
    },

    saveAsFileCancel() {
      this.saveAsModal = false;
    },
    //////////////////////////////////以上文件浏览功能//////////////////////////////////
    goBack() {
      this.$router.go(-1);
    },
    //
    save() {
      let self = this;
      self.data = [];
      let path = this.$api.processingApi.create;

      self.addData.taskParameter = JSON.stringify(self.addDataTaskParam);

      if (this.pushTaskType == "EmergencyTask") {
        self.addData.sourceId = 1;
      } else if (this.pushTaskType == "RoutineTask") {
        self.addData.sourceId = 2;
      } else if (this.pushTaskType == "ModisTask") {
        self.addData.sourceId = 3;
      } else {
        self.addData.sourceId = "";
      }

      //let param = JSON.stringify(self.addData);
      let param = {
        crontabExpress: self.addData.crontabExpress,
        // flowId: self.addData.flowId,
        // flowName: self.addData.flowName,
        sourceId: self.addData.sourceId,
        taskName: self.addData.taskName,
        status: 0,
        taskParameter: self.addData.taskParameter,
      };

      this.http.post(path, param).then((res) => {
        console.log("sss", res);
        if (res.data.success) {
          this.$emit("closeAddTask", false);
          self.pushTaskType = "EmergencyTask";
          self.sate = "";
          self.sensor = "";
          self.productName = "";
          self.resetAddData();
          self.sersorList = [];
          self.sateList = [];
          // 数组清空
          self.isShow = false;
          this.$Message.success("创建成功");

          this.cancle();
        } else {
          self.pushTaskType = "EmergencyTask";
          this.$Message.error(res.data.message);
        }
      });
    },
    //取消
    cancle() {
      let self = this;
      self.pushTaskType = "EmergencyTask";
      self.sate = "";
      self.sensor = "";
      self.productName = "";
      self.resetAddData();
      self.isShow = false;
      this.$emit("closeAddTask", false);
    },

    resetAddData() {
      let self = this;
      self.addData.taskName = "";
      self.addData.crontabExpress = "";
      self.addData.flowId = "";
      self.addData.flowName = "";
      self.addData.sourceId = 0;
      self.addData.taskParameter = "";

      self.addDataTaskParam.scanDir = "";
      self.addDataTaskParam.proDir = "";
      self.addDataTaskParam.finishFlag = ".gz";
      self.addDataTaskParam.taskOwner = "";
      self.addDataTaskParam.department = "";
      self.addDataTaskParam.enterId = -1;
      self.addDataTaskParam.orgId = -1;
      self.addDataTaskParam.userId = -1;
    },

    getCronList() {
      let path = this.$api.processingApi.getAllChildByDictCode;
      let param = {
        dictCode: "cron",
      };
      this.http.get(path, param).then((res) => {
        if (res.data.code == 0) {
          let dictCodeList = res.data.data.dictCodeList;
          this.cronList.push({ label: "请选择", value: "" });
          for (let dictCode of dictCodeList) {
            let cron = {
              label: dictCode.dictName,
              value: dictCode.dictCode,
            };
            this.cronList.push(cron);
          }
          console.log("1:", this.cronList);
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    getEnterpriseList() {
      let self = this;
      self.enterpriseList = [];
      let path = self.$api.processingApi.getTree;
      let param = {
        isTree: false,
      };
      this.http.get(path, param).then((res) => {
        if (res.data.success) {
          let content = res.data.data;
          for (let i = 0; i < content.length; i++) {
            let enterprise = {
              value: content[i].id,
              label: content[i].name,
            };
            self.enterpriseList.push(enterprise);
          }
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    selectEnterprise($event) {
      let self = this;

      self.addDataTaskParam.enterId = parseInt(event.target.value);
      self.getOrganizationList(self.addDataTaskParam.enterId);
    },
    getOrganizationList(enterpriseId) {
      let self = this;

      self.organizationList = [];
      let path = this.$api.processingApi.organization;
      let param = {
        enterId: enterpriseId,
        isTree: false,
      };

      this.http.get(path, param).then((res) => {
        if (res.data.success) {
          let content = res.data.data;

          for (let i = 0; i < content.length; i++) {
            let organization = {
              value: content[i].id,
              label: content[i].name,
            };
            self.organizationList.push(organization);
          }
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    selectOrganization($event) {
      let self = this;

      let selectedIndex = event.target.options.selectedIndex;
      let organizationName = event.target.options[selectedIndex].label;

      self.addDataTaskParam.orgId = parseInt(event.target.value);
      self.addDataTaskParam.department = organizationName;
      self.getUserNameList(self.addDataTaskParam.orgId);
    },
    getUserNameList(organizationId) {
      let self = this;
      self.userNameList = [];
      let path = self.$api.processingApi.queryAllUser;
      let param = {
        Authorization: window.sessionStorage.getItem("PIECloud-Token"),
        organizationId: organizationId,
      };

      this.http.get(path, param).then((res) => {
        if (res.data.success) {
          let content = res.data.data;

          for (let i = 0; i < content.userList.length; i++) {
            let userName = {
              value: content.userList[i].id,
              label: content.userList[i].username,
            };
            self.userNameList.push(userName);
          }
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    selectUserName($event) {
      let self = this;

      let selectedIndex = event.target.options.selectedIndex;
      let userName = event.target.options[selectedIndex].label;

      self.addDataTaskParam.userId = parseInt(event.target.value);
      self.addDataTaskParam.taskOwner = userName;
    },
  },
};
</script>
<style scoped>
.myCol {
  margin-left: 10px;
  display: flex;
  align-items: center;
}
.myColPri {
  width: 13%;
  margin-right: 10px;
}
.myCol1 {
  width: 90px;
  margin-left: 0px;
}
.myColtemp {
  display: flex;
  align-items: center;
}
.myColScan {
  display: flex;
  align-items: center;
}
.myColPro {
  display: flex;
  align-items: center;
  margin-left: -100px;
  left: 50px;
}
.search {
  display: flex;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.76563rem;
  line-height: 1.5;
  border-radius: 0.2rem;
  width: 50px;
}
.table-responsive {
  height: 50% !important;
}
.label {
  width: 80px;
  margin-right: 20px;
  margin-bottom: 15px;
  text-align: right;
}
.m_radio_group {
  height: 21px;
  width: 65%;
}
.m_radio_group label {
  margin: 0;
  margin-right: 1%;
}
.btnStyle {
  margin-right: 0px;
}
.strongstyle {
  font-size: 18px;
}
.cardstyle {
  margin-top: -20px;
  margin-left: 10px;
}
.rowstyle {
  margin-bottom: 20px;
}
.pickstyle {
  width: 50%;
}
 
.clean {
  margin-left: 10px;
}
.listbtn {
  margin-left: 0px;
}
.deletestyle {
  width: 15px;
  height: 15px;
}
.goBtn {
  margin-right: 10px;
}
.input {
  width: 300px;
  cursor: pointer;
}
</style>
<style lang='scss' scoped>
.table0 {
  width: 97%; // 611px;
  height: 324px;
  table-layout: fixed;
  border-top: 1px solid #dae1ea;
}
.jia {
  margin: -15px 0 1px -8px;
}
.optiostyle {
  height: 40px;
  width: 370px;
  float: right;
  font-size: 1rem;
  font-weight: bold;
  z-index: 99;
  margin-top: -50px;
}
.saveFileStyle {
  width: 280px;
}
.treeDiv {
  height: 500px;
  width: 760px;
  overflow-y: auto;
}
.treeDiv1 {
  height: 300px;
  width: 300px;
  overflow-y: auto;
}
.suffixBtn {
  margin-left: 10px;
}
.selectSuffix {
  float: left;
  width: 80%;
}
.inputTd {
  float: left;
  width: 80%;
  margin-bottom: 0px;
  margin-top: 4px;
}
.btnBrowser {
  float: right;
  margin-top: 4px;
  margin-bottom: 0px;
}
.btnSelectScanDir {
  width: 35px;
  height: 29px;
  margin-left: -90px;
  margin-top: 3px;
}
.btnSelectProDir {
  width: 35px;
  height: 29px;
  margin-left: -40px;
  margin-top: 3px;
}

.card-body {
  position: absolute;
  top: 62px !important;
  // overflow-y: auto;
}

.batchSelect {
  width: 550px;
  height: 200px;
  // overflow-x: auto;
  overflow-y: auto;
}
.levelDiv {
  width: 42px;
  float: left;
  padding-top: 6px;
  margin-left: 38px;
}
.inputRadio {
  width: 165px;
  margin-left: 10px;
}
.btn1 {
  margin: 0.3rem;
}
.footDiv {
  width: 100%;
  margin-top: -27px;
  z-index: 99;
}
.outLine {
  color: #3c6ef0;
  border-color: #3c6ef0;
  height: 40px;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
}
 
.position-relative {
  height: 360px;
  overflow: auto;
}
.card-header {
  height: 60px;
  padding: 0px;
  padding-top: 23px;
  padding-left: 23px;
}

.proTree {
  width: 50%;
  max-height: 480px;
  padding-right: 5px;
  overflow-y: scroll;
  margin-right: 15px;
}
::-webkit-scrollbar-thumb {
  background-color: #7eb8ee;
}
.productDiv {
  background-color: #fff;
  display: flex;
  width: 350px;
  position: absolute;
  // top: 68px;
  // right: 362px;
  top: 168px;
  right: 72px;
  border-left: 1px solid #d8d8d8;
  border-top: 1px solid #d8d8d8;
  border-bottom: 1px solid #d8d8d8;
  border-radius: 5px;
  bottom: 0;
}
.imgBtn {
  position: absolute;
  right: 11px;
  width: 16px;
  height: 16px;
  margin-top: 2px;
}
.tbHeader {
  width: 100%;
  display: inline-block;
}
.paramTable1 {
  display: none;
}
.cdHead {
  height: 60vh !important;
  border: none;
}
</style>
